package com.example.com.daervideo.myViews;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.com.daervideo.R;
import com.example.com.daervideo.databinding.FragmentVideoBinding;
import com.example.com.daervideo.utils.DensityUtil;


/**
 * Created by i7-1 on 2018/12/7.
 */

public class MyTab extends FrameLayout {


    private TextView left;
    private Context context;
    private float px18;
    private float px16;
    private TextView right;
    private View middle;

    public MyTab(Context context) {
        super(context);
    }

    public MyTab(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        intView(context);
    }


    public MyTab(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void intView(Context context) {
        this.context = context;
        View view = LayoutInflater.from(context).inflate(R.layout.my_tab, this, false);
        addView(view);
        left = view.findViewById(R.id.home);
        right = view.findViewById(R.id.my);
        middle = view.findViewById(R.id.publish);
        px18 = left.getTextSize();
        px16 = right.getTextSize();

    }

    public void setListener(final View.OnClickListener listener) {
        left.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!"1".equals(String.valueOf(left.getTag()))) {
                    left.setTextColor(context.getResources().getColor(R.color.white));
                    left.setTextSize(TypedValue.COMPLEX_UNIT_PX,px18);
                    right.setTextColor(context.getResources().getColor(R.color.mygrey));
                    right.setTextSize(TypedValue.COMPLEX_UNIT_PX ,px16);
                    listener.onClick(v);
                    left.setTag("1");
                }
            }
        });

        middle.setOnClickListener(listener);
        right.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("1".equals(String.valueOf(left.getTag()))) {
                    left.setTextColor(context.getResources().getColor(R.color.mygrey));
                    left.setTextSize(TypedValue.COMPLEX_UNIT_PX,px16);
                    right.setTextColor(context.getResources().getColor(R.color.white));
                    right.setTextSize(TypedValue.COMPLEX_UNIT_PX,px18);
                    listener.onClick(v);
                    left.setTag("0");
                }
            }
        });

    }
}
